﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using UcAsp.Net.BLL;
using UcAsp.Net.Model;
using System.IO;
namespace UcAsp.Net.Web.Controllers
{
    public class CourseController : Controller
    {
        //
        // GET: /Course/

        public ActionResult Index(int id)
        {
            BLL.SettingConfig.Theme(Request.UserAgent);
            int artid = id;
            ArticelsViews art = new ArticelsViews();
            int count;
            List<ArticelsViews> nextorprev;
            art = new ArticlesBLL().GetArtieById(artid, out count, out nextorprev);

            string view = "~/themes/" + BLL.SettingConfig.GetSiteSetting.Theme + "/Course/";
            Categories categories = new CategoriesBLL().GetCategoriesById(art.CategorieID);
            if (!string.IsNullOrEmpty(art.ViewsTemp.Trim()))
            {
                if (art.ViewsTemp.Trim() == "/")
                {
                    if (categories.ContentTempPath.Trim() == "/")
                    {
                        view = view + "index.cshtml";
                    }
                    else
                    {
                        view = view + categories.ContentTempPath + ".cshtml";
                    }
                }
                else
                {
                    view = view + art.ViewsTemp + ".cshtml";
                }
            }
            ViewData["Categories"] = categories;
            ViewData["Prev"] = nextorprev;
            return View(view, art);
        }
        public ActionResult SaveCourse(Course model)
        {
            BLL.SettingConfig.Theme(Request.UserAgent);
            new BLL.CourseBLL().Insert(model);
            Message messae = new Message { Result = true, Messages = "报名成功", Note1 = model.ActionId.ToString() };
            return Json(messae, JsonRequestBehavior.AllowGet);
        }
    }
}
